{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a4b0163f-e3e7-42cd-90a7-91d897905230",
   "metadata": {},
   "outputs": [],
   "source": [
    "%pip install git+https://github.com/alantech/marsha"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0270fd02-a572-4df9-a5c3-caa301a01714",
   "metadata": {},
   "outputs": [],
   "source": [
    "%env OPENAI_SECRET_KEY=sk-..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "18b4b4b3-fd42-40a8-97c7-98f05615ca52",
   "metadata": {},
   "outputs": [],
   "source": [
    "marsha_filename = 'employee_skills.mrsh'\n",
    "with open(marsha_filename, 'w') as f:\n",
    "    marsha_content = f'''\n",
    "# type EmployeesByDepartment ./employees_by_department.csv\n",
    "\n",
    "\n",
    "# type DepartmentSkills ./department_skills.csv\n",
    "\n",
    "\n",
    "# type EmployeeSkills\n",
    "name, skill\n",
    "Bob, math\n",
    "Jake, spreadsheets\n",
    "Lisa, coding\n",
    "Sue, spreadsheets\n",
    "\n",
    "\n",
    "# func get_employee_skills(list of EmployeesByDepartment, list of DepartmentSkills): list of EmployeeSkills\n",
    "\n",
    "This function receives a list of EmployeesByDepartment and a list of DepartmentSkills. \n",
    "The function should be able to create a response of EmployeeSkills merging the 2 list by department.\n",
    "Use the pandas library.\n",
    "\n",
    "* get_employee_skills() = throws an error\n",
    "* get_employee_skills([EmployeesByDepartment('Joe', 'Accounting')]) = throws an error\n",
    "* get_employee_skills([], []) = []\n",
    "* get_employee_skills([EmployeesByDepartment('Joe', 'Accounting')], []) = []\n",
    "* get_employee_skills([], [DepartmentSkills('Accounting', 'math')]) = []\n",
    "* get_employee_skills([EmployeesByDepartment('Joe', 'Accounting')], [DepartmentSkills('Accounting', 'math')]) = [EmployeeSkills('Joe', 'math')]\n",
    "* get_employee_skills([EmployeesByDepartment('Joe', 'Accounting'), EmployeesByDepartment('Jake', 'Engineering')], [DepartmentSkills('Accounting', 'math')]) = [EmployeeSkills('Joe', 'math')]\n",
    "* get_employee_skills([EmployeesByDepartment('Joe', 'Accounting'), EmployeesByDepartment('Jake', 'Engineering')], [DepartmentSkills('Accounting', 'math'), DepartmentSkills('Engineering', 'coding')]) = [EmployeeSkills('Joe', 'math'), EmployeeSkills('Jake', 'coding')]\n",
    "\n",
    "\n",
    "# func read_csv_file(path to file): file data without header\n",
    "\n",
    "This function read a CSV file and return the csv content without header.\n",
    "\n",
    "\n",
    "# func process_data(path to file with EmployeesByDepartment, path to file with DepartmentSkills): list of EmployeeSkills\n",
    "\n",
    "This function uses `read_csv_file` to read the 2 csv files received and create the respective lists. Make sure to strip and lower each string property coming from the csv. Then, call and return the result from `get_employee_skills`.\n",
    "\n",
    "* process_data('/pathA', '') = throws an error\n",
    "* process_data('/pathA', '/pathB') = [EmployeeSkills('Joe', 'math')]\n",
    "* process_data('/pathA', 'pathC') = [EmployeeSkills('Joe', 'math'), EmployeeSkills('Jake', 'coding')]\n",
    "'''\n",
    "    f.write(marsha_content)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "20544e71-9869-4898-98bd-04b5431529bf",
   "metadata": {},
   "outputs": [],
   "source": [
    "!python -m marsha ./\"$marsha_filename\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0658fd25-948b-4c98-a443-4a5b63b18073",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Install marsha generated code requirements\n",
    "%pip install -r requirements.txt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3e69c211-20b1-47b5-8e4c-7c5c20589974",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Install additional dependencies\n",
    "%pip install matplotlib"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "407a780a",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "from employee_skills import process_data\n",
    "\n",
    "employee_skills_list = process_data('./employees_by_department.csv', './department_skills.csv')\n",
    "employee_skills_df = pd.DataFrame([(e.name, e.skill) for e in employee_skills_list], columns=[\"Name\", \"Skill\"])\n",
    "skill_counts = employee_skills_df[\"Skill\"].value_counts()\n",
    "\n",
    "plt.figure(figsize=(8, 4))\n",
    "plt.pie(skill_counts, labels=skill_counts.index, autopct=\"%1.1f%%\")\n",
    "plt.title(\"Employee Skills\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "daa6ebc5-1bd9-455e-beb9-dabfbc4ca1f4",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
